package stackexchange.posts;

import java.util.Calendar;

public class Answer extends Post {

	private int parentId;
	private boolean anAcceptedAnswer = false;
	private boolean anMostRatedAnswer = false;

	public Answer(int postId, Calendar creationDate, int score, String body,
			int ownedUserId, Calendar lastEditDate, Calendar lastActivityDate,
			int nComments, int parentId) {
		super(postId, creationDate, score, body, ownedUserId, lastEditDate,
				lastActivityDate, nComments);

		this.parentId = parentId;
	}

	public int getParentId() {
		return parentId;
	}

	public boolean isAnAcceptedAnswer() {
		return anAcceptedAnswer;
	}

	public void setAnAcceptedAnswer(boolean anAcceptedAnswer) {
		this.anAcceptedAnswer = anAcceptedAnswer;
	}

	public boolean isAnMostRatedAnswer() {
		return anMostRatedAnswer;
	}

	public int getSuppliedReputation() {
		int score = 10 * this.score;
		if (this.isAnAcceptedAnswer()) {
			return score + 15;
		}
		return score;
	}

	public double getWeight() {

		double scoreCoef = 1;
		if (this.isAnAcceptedAnswer() && this.isAnMostRatedAnswer()) {
			scoreCoef = 15;
		} else if (this.isAnAcceptedAnswer()) {
			scoreCoef = 10;
		} else if (this.isAnMostRatedAnswer()) {
			scoreCoef = 11;
		} else {
			scoreCoef = 1;
		}
		if (this.isCommented()) {
			scoreCoef = scoreCoef + 2;
		}
		if (this.isEdited()) {
			scoreCoef = scoreCoef + 2;
		}
		return scoreCoef;
	}

	public void setAnMostRatedAnswer(boolean anMostRatedAnswer) {
		this.anMostRatedAnswer = anMostRatedAnswer;
	}

}
